import { useMainStore } from '@/stores/main';
import { equalRow } from './utils/utils';
const store = useMainStore();
const ageOptions = () => {
  return JSON.parse(JSON.stringify([{ data: { vals: [], sVal: '' } }]));
};
//'' < 数字 < 字符 < null < undefined
const sortBy = ({ column, row }: { column: any; row: any }) => {
  const fixRow = Array.from(store.$state.fixRow ?? []);
  if (fixRow.some(item => equalRow(item, row))) {
    if (column.order === 'asc') {
      return null;
    } else if (column.order === 'desc') {
      return undefined;
    }
  }
  return row[column.field]?.trim();
};

export const columnsData = [
  { type: 'checkbox', width: 60, fixed: 'left' },
  { field: 'xuhao', title: '序号', width: 100, cellType: 'string', fixed: 'left' },
  {
    field: 'areaName',
    title: '台区名称',
    width: 160,
    showOverflow: true,
    filters: ageOptions(),
    sortBy: sortBy,
    sortable: true,
    filterRender: { name: 'FilterContent' },
    type: 'html',
  },
  {
    field: 'management',
    title: '管理单位',
    width: 160,
    showOverflow: true,
    filters: ageOptions(),
    sortBy: sortBy,
    sortable: true,
    filterRender: { name: 'FilterContent' },
    type: 'html',
  },
  {
    field: 'eletricAssetsNumber',
    title: '电能表资产号',
    width: 220,
    showOverflow: true,
    filters: ageOptions(),
    sortBy: sortBy,
    sortable: true,
    filterRender: { name: 'FilterContent' },
    type: 'html',
  },
  {
    field: 'deviceType',
    width: 160,
    title: '设备类型',
    editRender: {},
    slots: { edit: 'role_edit' },
    type: 'html',
  },
  {
    field: 'deviceDesc',
    width: 320,
    title: '设备类型描述',
    showOverflow: true,
    type: 'html',
  },
  {
    field: 'status',
    title: '状态',
    width: 120,
    filters: ageOptions(),
    sortBy: sortBy,
    filterRender: { name: 'FilterContent' },
    slots: { default: 'status' },
    type: 'html',
  },
  {
    field: 'startDate',
    title: '开始时间',
    width: 160,
    showOverflow: true,
    filters: ageOptions(),
    sortBy: sortBy,
    sortable: true,
    filterRender: { name: 'FilterContent' },
    type: 'html',
  },
  {
    field: 'operatorTime',
    title: '操作时间',
    width: 160,
    showOverflow: true,
    sortable: true,
    sortBy: sortBy,
    filters: ageOptions(),
    filterRender: { name: 'FilterContent' },
    type: 'html',
  },
  {
    field: 'updateTime',
    title: '更新时间',
    width: 220,
    showOverflow: true,
    sortable: true,
    filters: ageOptions(),
    sortBy: sortBy,
    filterRender: { name: 'FilterContent' },
    type: 'html',
  },
  {
    field: 'parameterValue',
    title: '参数值',
    showOverflow: true,
    filters: ageOptions(),
    filterRender: { name: 'FilterContent' },
    sortBy: sortBy,
    width: 120,
    type: 'html',
    align: 'center',
  },
  {
    width: 220,
    fixed: 'right',
    field: 'operator',
    title: '操作',
    slots: { default: 'operator_buttons' },
  },
];
